package com.heyqing.topic.MaxDepth_0104;

import java.util.Objects;

/**
 * ClassName:MaxDepth
 * Package:com.heyqing.topic.MaxDepth_0104
 * Description:
 *
 * @Date:2024/9/12
 * @Author:Heyqing
 */
public class MaxDepth {

    private int depth = 0;
    public int maxDepth(TreeNode root) {
        getMaxDepth(root,0);
        return depth;
    }
    private void getMaxDepth(TreeNode root, int currentDepth) {
        if (Objects.isNull(root)){
            return;
        }
        currentDepth++;
        if (Objects.isNull(root.left) && Objects.isNull(root.right)){
            depth = Math.max(currentDepth,depth);
        }
        getMaxDepth(root.left,currentDepth);
        getMaxDepth(root.right,currentDepth);
    }

}
